import random
from pypinyin import lazy_pinyin
import datetime
import tkinter as tk
from tkinter import filedialog
#随机生成名字
def c_name():
    first_name = random.choice('谭')
    head1 = random.randint(0xb0, 0xf7)
    body1 = random.randint(0xa1, 0xf9)
    vaa = f'{head1:x}{body1:x}'
    secound_name = bytes.fromhex(vaa).decode('gb2312')
    head2 = random.randint(0xb0, 0xf7)
    body2 = random.randint(0xb0, 0xf7)
    vab = f'{head2:x}{body2:x}'
    last_name = bytes.fromhex(vab).decode('gb2312')
    name = first_name + secound_name + last_name
    return name

def creat_str():
    head = random.randint(0xb0, 0xf7)
    body = random.randint(0xa1, 0xf9)
    vaa = f'{head:x}{body:x}'
    str = bytes.fromhex(vaa).decode('gb2312')
    return str

#随机生成拼音
def spell_name(name):
    a = ""
    b = lazy_pinyin(name)
    for c in b:
        a += c
    return a

#随机生成手机号码
def generate_phone():
    sec = [3, 4, 5, 7, 8][random.randint(0, 4)]
    th = {
        3: random.randint(0, 9),
        4: [a for a in range(5, 10)][random.randint(0, 4)],
        5: [a for a in range(10) if a != 4][random.randint(0, 7)],
        7: [a for a in range(8)][random.randint(0, 7)],
        8: random.randint(0, 9)
    }[sec]
    end = random.randint(10000000, 99999999)
    phone = '1{0}{1}{2}'.format(sec, th, end)
    return phone

#随机生成邮箱
def email(name):
    n = spell_name(name)
    list = ['@talebase.com', '@thb.com', '@mzt.com']
    acc = random.choice(list)
    acc = str(acc)
    c = ""
    for a in n:
        c += a
    email = c + acc
    return email

#随机生成性别
def create_sex():
    sex = random.choice('男女')
    return sex

def create_occupation():
    occ = random.choice('')
    return occ

#随机生成年龄
def create_age():
    age = random.randint(18, 27)
    return str(age)

#随机生成个人信息
def create_msg():
    name = c_name()
    msg = "名字：" + name + "\n" + "性别：" + create_sex() + "\n" + "年龄：" + create_age() + "岁" + "\n" + "手机号码：" + generate_phone() + "\n" + "邮箱：" + email(name)
    return msg

#生成当前时间
def new_time():
    time = datetime.date.today()
    return time

def assess():
    list = ['上级', '平级', '下属']
    acc = random.choice(list)
    return acc

#图形化保存文件
def save_file():
    root = tk.Tk()
    root.withdraw()
    Fpath = filedialog.asksaveasfilename()
    return Fpath

#图形化读取
def open_file():
    root = tk.Tk()
    root.withdraw()
    Fpath = filedialog.askopenfilename()
    return Fpath







